package day04;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/18
 */
public class Binary {
    public static int binarySearch(int[] arr, int target) {
        int mid;
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            mid = (left + right) / 2;
            if (target == arr[mid]) {
                return mid;
            } else if (target < arr[mid]) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}
